home *** CD-ROM | disk | FTP | other *** search
- Path: fontina.cs.wisc.edu!flisakow
- From: flisakow@fontina.cs.wisc.edu (Shaun Flisakowski)
- Newsgroups: comp.lang.c
- Subject: Re: ???Recursive Function needed for string printing
- Date: 7 Feb 1996 09:42:52 GMT
- Organization: U of Wisconsin CS Dept
- Message-ID: <4f9s6s$bb4@spool.cs.wisc.edu>
- References: <4f44eo$74u@upsidedown.MTS.Net>
- NNTP-Posting-Host: fontina.cs.wisc.edu
-
- In article <4f44eo$74u@upsidedown.MTS.Net>, George <bwilliam@MTS.Net> wrote:
- >How do I write a recursive function to print a string using only
- >printf and %c to print it out.
- >
- >George at bwilliam@MTS.Net
-
- Hope you don't mind if I combine a few threads, this is a pretty
- busy group, you know.
-
- The following prints a string, given as the 1st command line argument
- to the program, using printf with only %c.
-
- This is also a valid answer to the "can I call main()" thread,
- as well as a hint for the "how do I stop recursing" thread,
- (the answer of course, is to stop when the string is printed).
-
-
- #include <stdio.h>
- #include <string.h>
-
- int main(int ac, char **av) {
-
- if ( ac = (ac > 0) ? (-strlen(av[1])) : ac+1)
- main(ac,av);
-
- printf("%c", *(av[1]-ac-1) );
-
- if (!strlen(av[1]-ac))
- printf("%c", '\n' );
-
- return(0);
- }
-
- Good luck with your class, and please feel free to send me huge
- gobs of money.
-
- PS: In the future, try cross-posting, I've read these message
- 3 times already. Also, it is not appropriate for comp.programming.
-
- --
- Shaun flisakow@cs.wisc.edu
-
- "In your heart you know its flat."
- -Flat Earth Society
-